home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / TUTORIAL.BIN / BigInt.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-01-30  |  4.1 KB  |  142 lines

  1. package symantec.itools.db.net;
  2.  
  3. import java.io.DataOutputStream;
  4. import java.io.IOException;
  5. import symjava.lang.Bignum;
  6. import symjava.sql.SQLException;
  7.  
  8. public class BigInt extends NumberField {
  9.    long _iVal;
  10.  
  11.    BigInt() {
  12.    }
  13.  
  14.    int getType() {
  15.       return 78;
  16.    }
  17.  
  18.    void readData(ServerObject data) throws SQLException, IOException, ErrorException {
  19.       this._iVal = ((NetData)data).getLong();
  20.    }
  21.  
  22.    void writeData(DataOutputStream os) throws IOException {
  23.       NetData data = new NetData(this._iVal);
  24.       data.write(os);
  25.    }
  26.  
  27.    public String getString() throws SQLException {
  28.       return ((Field)this).isNull() ? null : String.valueOf(this._iVal);
  29.    }
  30.  
  31.    public boolean getBoolean() throws SQLException {
  32.       if (((Field)this).isNull()) {
  33.          return false;
  34.       } else {
  35.          return this._iVal != 0L;
  36.       }
  37.    }
  38.  
  39.    public byte getByte() throws SQLException {
  40.       return ((Field)this).isNull() ? 0 : (byte)((int)this._iVal);
  41.    }
  42.  
  43.    public short getShort() throws SQLException {
  44.       return ((Field)this).isNull() ? 0 : (short)((int)this._iVal);
  45.    }
  46.  
  47.    public int getInt() throws SQLException {
  48.       return ((Field)this).isNull() ? 0 : (int)this._iVal;
  49.    }
  50.  
  51.    public long getLong() throws SQLException {
  52.       return ((Field)this).isNull() ? 0L : this._iVal;
  53.    }
  54.  
  55.    public float getFloat() throws SQLException {
  56.       if (((Field)this).isNull()) {
  57.          return 0.0F;
  58.       } else {
  59.          Float f = new Float((float)this._iVal);
  60.          return f;
  61.       }
  62.    }
  63.  
  64.    public double getDouble() throws SQLException {
  65.       if (((Field)this).isNull()) {
  66.          return (double)0.0F;
  67.       } else {
  68.          Double f = new Double((double)this._iVal);
  69.          return f;
  70.       }
  71.    }
  72.  
  73.    public Bignum getBignum(int scale) throws SQLException {
  74.       return ((Field)this).isNull() ? null : new Bignum(this._iVal, scale);
  75.    }
  76.  
  77.    public void setBoolean(boolean x) throws SQLException {
  78.       if (x) {
  79.          this._iVal = 1L;
  80.       } else {
  81.          this._iVal = 0L;
  82.       }
  83.  
  84.       super._null = false;
  85.    }
  86.  
  87.    public void setByte(byte x) throws SQLException {
  88.       this._iVal = (long)x;
  89.       super._null = false;
  90.    }
  91.  
  92.    public void setShort(short x) throws SQLException {
  93.       this._iVal = (long)x;
  94.       super._null = false;
  95.    }
  96.  
  97.    public void setInt(int x) throws SQLException {
  98.       this._iVal = (long)x;
  99.       super._null = false;
  100.    }
  101.  
  102.    public void setLong(long x) throws SQLException {
  103.       this._iVal = x;
  104.       super._null = false;
  105.    }
  106.  
  107.    public void setFloat(float x) throws SQLException {
  108.       Float f = new Float(x);
  109.       this._iVal = f.longValue();
  110.       super._null = false;
  111.    }
  112.  
  113.    public void setDouble(double x) throws SQLException {
  114.       Double d = new Double(x);
  115.       this._iVal = d.longValue();
  116.       super._null = false;
  117.    }
  118.  
  119.    public void setBignum(Bignum x) throws SQLException {
  120.       this._iVal = x.longValue();
  121.       super._null = false;
  122.    }
  123.  
  124.    public void setString(String x) throws SQLException {
  125.       Integer i = new Integer(x);
  126.       this._iVal = i.longValue();
  127.       super._null = false;
  128.    }
  129.  
  130.    public int getSQLType() {
  131.       return -5;
  132.    }
  133.  
  134.    public Object getObject() throws SQLException {
  135.       return new Long(this._iVal);
  136.    }
  137.  
  138.    public void setObject(Object obj) throws SQLException {
  139.       this.setLong((Long)obj);
  140.    }
  141. }
  142.